package com.ruoyi.web.controller.tongban;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tongban.domain.SysAgreement;
import com.ruoyi.tongban.service.ISysAgreementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 协议内容Controller
 * 
 * @author ruoyi
 * @date 2021-05-27
 */
@RestController
@RequestMapping("/tongban/agreement")
public class SysAgreementController extends BaseController
{
    @Autowired
    private ISysAgreementService sysAgreementService;

    /**
     * 查询协议内容列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:agreement:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAgreement sysAgreement)
    {
        startPage();
        List<SysAgreement> list = sysAgreementService.selectSysAgreementList(sysAgreement);
        return getDataTable(list);
    }

    /**
     * 导出协议内容列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:agreement:export')")
    @Log(title = "协议内容", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysAgreement sysAgreement)
    {
        List<SysAgreement> list = sysAgreementService.selectSysAgreementList(sysAgreement);
        ExcelUtil<SysAgreement> util = new ExcelUtil<SysAgreement>(SysAgreement.class);
        return util.exportExcel(list, "agreement");
    }

    /**
     * 获取协议内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:agreement:query')")
    @GetMapping(value = "/{agreementId}")
    public AjaxResult getInfo(@PathVariable("agreementId") Long agreementId)
    {
        return AjaxResult.success(sysAgreementService.selectSysAgreementById(agreementId));
    }

    /**
     * 新增协议内容
     */
    @PreAuthorize("@ss.hasPermi('tongban:agreement:add')")
    @Log(title = "协议内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAgreement sysAgreement)
    {
        return toAjax(sysAgreementService.insertSysAgreement(sysAgreement));
    }

    /**
     * 修改协议内容
     */
    @PreAuthorize("@ss.hasPermi('tongban:agreement:edit')")
    @Log(title = "协议内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAgreement sysAgreement)
    {
        return toAjax(sysAgreementService.updateSysAgreement(sysAgreement));
    }

    /**
     * 删除协议内容
     */
    @PreAuthorize("@ss.hasPermi('tongban:agreement:remove')")
    @Log(title = "协议内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agreementIds}")
    public AjaxResult remove(@PathVariable Long[] agreementIds)
    {
        return toAjax(sysAgreementService.deleteSysAgreementByIds(agreementIds));
    }
}
